// pages/logistics/logistics.js
var that,
  api = new (require('../../utils/api.js')),
  headimg = api.getimgurl(),
  app = getApp(),
  util = new (require('../../utils/util.js')),
  tabbars = ['ALL', 'NO_PAY', 'PAY_SUCCESS', 'SHIPPED', 'RECEIVED', 'SOLVING', 'SOLVED','CANCELED'];
Page({

  /**
   * 页面的初始数据
   */
  data: {
     Traces:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that=this
    console.log(options);
    let {lcode}=options,{Traces}=that.data
       api.orderdistinguish(lcode,res=>{
            if(res.data.issuccess==1){
                console.log(res.data.data,'res.data.data');
//               let data = JSON.parse(res.data.data)
                let data = JSON.parse(res.data.data)
              console.log(data,'data');
              let { Shippers } = data;
              if (Shippers.length>0){
                api.traceorder({lcode, scode:Shippers[0]['ShipperCode']},res=>{
                  wx.hideLoading()
                  let data = JSON.parse(res.data.data),{ShipperCode,LogisticCode}=data
                  api.orderTracesSubByJson({ShipperCode,LogisticCode},res=>{
                      if(res.data.issuccess==1){
                        
                      }
                  });
                  if(data.Traces.length>0){
                    that.setData({ Traces: data.Traces})
                  }
                })
              }
            }else{
              wx.hideLoading()
              wx.showModal({
                title: '提示',
                content: '查询有误，请稍后再试',
                showCancel:!1
              })
            }
      
          })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})